﻿using System;
using System.Data.SqlTypes;
using BMServiceGenerator.Tests.ApprovedInvoicesService;
using NUnit.Framework;

namespace BMServiceGenerator.Tests
{
    /// <summary>
    /// Note that this is a integration test. It requires a deployed service with namespace Test.Test and the test activity within the project to be deployed.
    /// </summary>
    [TestFixture]
    public class ApprovedInvoicesActivityTests
    {
        [Test]
        public void LogCompleteApprovedInvoicesServiceTest()
        {
            var srv = new ApprovedInvoicesServiceClient();
            string activityId = Guid.NewGuid().ToString();

            srv.LogCompleteActivity(activityId, new ApprovedInvoicesServiceType() { Amount = 1, ApprovedBy = "xx", ApprovedDate = DateTime.Now, InvoiceId = "1001" });
        }

        [Test]
        public void UpdatedApprovedInvoicesServiceTest()
        {
            string activityId = Guid.NewGuid().ToString();

            var srv = new ApprovedInvoicesServiceClient();
            srv.BeginActivity(activityId);
            srv.UpdateActivity(activityId, new ApprovedInvoicesServiceType() { Amount = 2, ApprovedDate = SqlDateTime.MinValue.Value, InvoiceId = "1001" });
            srv.UpdateActivity(activityId, new ApprovedInvoicesServiceType() { Amount = 2, ApprovedBy = "xx", ApprovedDate = DateTime.Now });
            srv.EndActivity(activityId);
        }

        [Test]
        public void ContinuatedApprovedInvoicesServiceTest()
        {
            string activityId = Guid.NewGuid().ToString();
            var invoiceId = string.Concat("InvoiceId#", new Random().Next(0, 10000));

            var firstSrv = new ApprovedInvoicesServiceClient();
            firstSrv.BeginActivity(activityId);
            firstSrv.UpdateActivity(activityId, new ApprovedInvoicesServiceType() { Amount = 2, ApprovedDate = SqlDateTime.MinValue.Value, InvoiceId = invoiceId });
            firstSrv.EnableContinuation(activityId, invoiceId);
            firstSrv.EndActivity(activityId);

            var secondSrv = new ApprovedInvoicesServiceClient();
            secondSrv.BeginActivity(invoiceId);
            secondSrv.UpdateActivity(invoiceId, new ApprovedInvoicesServiceType() { Amount = 2, ApprovedBy = "xx", ApprovedDate = DateTime.Now });
            secondSrv.EndActivity(invoiceId);
        }

    }
}
